﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Data.Items;
using System.Data;
using Workflow.Alerts.DAL;
using Workflow.Alerts.Interfaces.ProfileSettings;

namespace Workflow.Alerts
{
    public class PersonListPresenter : Presenter
    {
        #region members
        private readonly PersonDAL model;
        private readonly IPersonListView view;
        #endregion

        #region constructor
        public PersonListPresenter(IPersonListView _view)
            : this(_view, null)
        { }

        public PersonListPresenter(IPersonListView _view, ISessionProvider session)
            : base(_view, session)
        {
            view = base.GetView<IPersonListView>();
            view.OnPageLoad += view_OnLoad;
            model = new PersonDAL();
        }

        #endregion

        #region private methods

        private void view_OnLoad()
        {
            var filter = new WorkflowFilter
            {
                NetworkOperatorId = view.NetworkOperatorId
            };

            var filterSql = new WorkflowFilterSql(filter);

            DataTable contacts = model.GetNetworkOperatorPersonList(filterSql, true);

            view.Contacts = contacts;
        }

        #endregion
    }
}
